package com.net128.beatportapps.downloader;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;

public class PreferencesDialog extends AppDialog {
	private static String[] preferencesOptionNames = { "OK", "Cancel" };
	private static String preferencesTitle = "Preferences";
	boolean firstInput = true;
	private JComboBox maxParallelDownloads = new JComboBox(new Integer[] { 1, 5, 12, 24, 36 });
	private JTextField downloadDirectoryField = new JTextField();
	private JTextField outputFileNameField = new JTextField();

	public void edit() {
		addInput("Max. parallel downloads", maxParallelDownloads, 50);

		JButton chooseDir = new JButton("...");
		chooseDir.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				JFileChooser fileChooser = new JFileChooser();
				fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
				fileChooser.setDialogTitle("Download Directory Chooser");
				fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
				fileChooser.setAcceptAllFileFilterUsed(false);
				if (fileChooser.showOpenDialog(downloadDirectoryField) == JFileChooser.APPROVE_OPTION) {
					downloadDirectoryField.setText(fileChooser.getSelectedFile().getAbsolutePath());
				}
			}
		});

		JPanel dirChooserPanel = new JPanel(new BorderLayout(2, 0));
		dirChooserPanel.add(chooseDir, BorderLayout.EAST);
		dirChooserPanel.add(downloadDirectoryField, BorderLayout.CENTER);
		addInput("Download directory", dirChooserPanel, 500);
		addInput("Output file name", outputFileNameField, -1);

		if (showOptionDialog(preferencesTitle, JOptionPane.OK_CANCEL_OPTION, preferencesOptionNames,
			preferencesOptionNames[0], downloadDirectoryField) == JOptionPane.OK_OPTION) {
			//no action
		}
	}
}